package vip

import (
	"strconv"

	"github.com/gogf/gf/v2/net/ghttp"

	bmodel "github.com/beherochuling/beesoft_api/app/model"
	model "github.com/beherochuling/beesoft_api/app/model/vip"
	service "github.com/beherochuling/beesoft_api/app/service/curd/vip"

	"github.com/beherochuling/beesoft_api/app/helper/net"
	"github.com/beherochuling/beesoft_api/app/service/util"
)

var Activity = activity{}

type activity struct{}

func (activity) List(r *ghttp.Request) { // 列表
	var req *model.ActivityListRequest
	util.ParseRequest(r, &req)
	res := net.NewResponse(r)

	result, total := service.Activity.List(r.Context(), req)
	if result == nil {
		// res.ResponseException("1")
	}

	res.SetHeader(bmodel.HeaderTotal, strconv.Itoa(total)).
		ResponseOk(result)
}
func (activity) Show(r *ghttp.Request) { // 详情
	id := r.Get("id").Uint()
	if id == 0 {
		panic("id is required")
	}

	err := service.Activity.Show(r.Context(), id)
	if err != nil {
		return
	}

	net.NewResponse(r).ResponseOk()
}
func (activity) Store(r *ghttp.Request) { // 创建
	var req *model.ActivityStoreRequest
	util.ParseRequest(r, &req)

	err := service.Activity.Store(r.Context(), req)
	if err != nil {
		return
	}

	net.NewResponse(r).ResponseOk()
}
func (activity) Update(r *ghttp.Request) { // 更新
	var req *model.ActivityUpdateRequest
	util.ParseRequest(r, &req)

	err := service.Activity.UpdateById(r.Context(), req.Id, req)
	if err != nil {
		return
	}

	net.NewResponse(r).ResponseOk()
}
func (activity) Destroy(r *ghttp.Request) { // 删除
	id := r.Get("id").Uint()
	if id == 0 {
		panic("id is required")
	}

	err := service.Activity.DestroyById(r.Context(), id)
	if err != nil {
		return
	}

	net.NewResponse(r).ResponseOk()
}
